<?php
declare(strict_types=1);

namespace LowCode\Traits\Vue;

trait HasStyle
{
    public function addStyle($styleClass, string|array $styleBody): static
    {
        $style = $styleBody;
        if (is_array($styleBody)){
            $styles = [];
            foreach ($styleBody as $key=>$value){
                $styles[] = "$key:$value;";
            }
            $style = implode("",$styles);
        }
        $this->builder->style->put($styleClass,"$styleClass{{$style}}");
        return $this;
    }

    protected function getStyleHtml(): string
    {
        $styles = $this->builder->style->all();
        $style = "";
        if ($styles){
            $style = implode("",$styles);
        }
        return "<style scoped>$style</style>";
    }
}
